package com.example.administrator.yanfoxconn.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.administrator.yanfoxconn.R;
import com.example.administrator.yanfoxconn.activity.KNGreenUpProjectActivity;
import com.example.administrator.yanfoxconn.activity.LCMainUpActivity;
import com.example.administrator.yanfoxconn.bean.KMDMT;
import com.example.administrator.yanfoxconn.bean.KNZWGreen;
import com.example.administrator.yanfoxconn.bean.LCMessage;

import java.util.List;

/**
 * @Description
 * @Author song
 * @Date 11/9/21 7:58 PM
 */
public class KMDMTBoxAdapter extends BaseAdapter {
    List<KMDMT> list;
    List<KNZWGreen> zwlist;
    List<LCMessage> lclist;
        Context context;
        KNGreenUpProjectActivity activity;
        String from="";

    public KMDMTBoxAdapter(List<KMDMT> list, Context context,String from) {
        // TODO Auto-generated constructor stub
        this.list=list;
        this.context=context;
        this.from = from;

    }
    public KMDMTBoxAdapter(List<KNZWGreen> list, KNGreenUpProjectActivity context,String from) {
        // TODO Auto-generated constructor stub
        this.zwlist=list;
        this.context=context;
        this.from = from;
    }
    public KMDMTBoxAdapter(List<LCMessage> list, LCMainUpActivity context, String from) {
        // TODO Auto-generated constructor stub
        this.lclist=list;
        this.context=context;
        this.from = from;
    }

        public int getCount() {
            // TODO Auto-generated method stub
            if (from.equals("kn")){
                return zwlist.size();
            }else if (from.equals("lc")){
                return lclist.size();
            }else{
            return list.size();}
        }

        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return null;
        }

        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return 0;


        }

    public View getView(final int position, View convertView, ViewGroup parent)
    {
        // TODO Auto-generated method stub
        final ViewHolder viewHolder;
        if(convertView==null){
            convertView=View.inflate(context, R.layout.adapter_dmt_box_lv, null);
            viewHolder=new ViewHolder();
            viewHolder.rlBkg=(RelativeLayout)convertView.findViewById(R.id.rl_bkg);
            viewHolder.textView=(TextView) convertView.findViewById(R.id.text);
            viewHolder.textView2=(TextView) convertView.findViewById(R.id.text_2);
            viewHolder.checkBox=(CheckBox) convertView.findViewById(R.id.checkbox);
            convertView.setTag(viewHolder);
        }else{
            viewHolder=(ViewHolder) convertView.getTag();
        }
        String seed="";
        if (from.equals("kn")){
            for (int i=0;i<zwlist.get(position).getBody().size();i++){
                if (i==0){    seed=zwlist.get(position).getBody().get(i).getGsName()+zwlist.get(position).getBody().get(i).getGsNum()+zwlist.get(position).getBody().get(i).getGsUnit();
                }else{
                seed=seed+"\n"+zwlist.get(position).getBody().get(i).getGsName()+zwlist.get(position).getBody().get(i).getGsNum()+zwlist.get(position).getBody().get(i).getGsUnit();
            }}
            viewHolder.textView.setText(zwlist.get(position).getGcName() +"共計"+zwlist.get(position).getGcNum()+zwlist.get(position).getGcUnit());
            viewHolder.textView2.setText(seed);
            viewHolder.textView2.setVisibility(View.VISIBLE);
            if (zwlist.get(position).getFlag().equals("Y")){
                //显示checkBox
                viewHolder.checkBox.setChecked(zwlist.get(position).getBo()); //显示checkBox
                viewHolder.checkBox.setVisibility(View.VISIBLE);
                viewHolder.textView.setTextColor(context.getResources().getColor(R.color.blank));
                        viewHolder.textView2.setTextColor(context.getResources().getColor(R.color.blank));
            }else{

                viewHolder.textView.setTextColor(context.getResources().getColor(R.color.color_858585));
                viewHolder.textView2.setTextColor(context.getResources().getColor(R.color.color_858585));
                //显示checkBox
                viewHolder.checkBox.setVisibility(View.GONE);
            }
        }else if(from.equals("lc")){
            viewHolder.textView.setText(lclist.get(position).getPoint_name() );
            //显示checkBox
            viewHolder.checkBox.setChecked(lclist.get(position).getBo());
        }else {
            viewHolder.textView.setText(list.get(position).getM_kind() + list.get(position).getM_model());
            //显示checkBox
            viewHolder.checkBox.setChecked(list.get(position).getBo());
        }

        return convertView;

    }
    public class ViewHolder{
        public RelativeLayout rlBkg;
        public TextView textView,textView2;
        public CheckBox checkBox;
    }

}
